package src.threadpool;

/**
 * 演示newFixedThreadPool出错的情况
 */
public class FixedThreadPoolOOM {
    public static void main(String[] args) {
        // 创建一个固定大小的线程池
        java.util.concurrent.ExecutorService executorService = java.util.concurrent.Executors.newFixedThreadPool(1);

        // 提交多个任务
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            executorService.execute(new Task());
        }
    }

    static class Task implements Runnable {
        @Override
        public void run() {
            try {
                // 模拟任务执行
                Thread.sleep(10000000);
                System.out.println("执行了任务");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
